/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.guias.data;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;

/**
 *
 * @author Joshua
 */
public abstract class Conexion {
    
    protected Connection conn= null;
    protected PreparedStatement pstm = null;
    protected ResultSet rst = null;
    
    public void CrearConexion() throws Exception{
        try{
            ResourceBundle rb = ResourceBundle.getBundle("com.guias.utilidades.init");
            String basedatos = rb.getString("basedatos");
            String usuario = rb.getString("usuario");
            String password = rb.getString("password");
            Class.forName("com.mysql.jdbc.Driver");
            conn = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1/"+basedatos,usuario,password);
            
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
    
    public void CerrarConexion() throws SQLException{
        if (conn!=null){
            if(conn.isClosed()==false){
                conn.close();
            }
        }
        if (pstm != null){
            pstm.close();
        }
    }
}
